package ui.panel;

import entity.CommonParam;
import ui.common.CommonPanel;
import ui.label.HeaderLabel;
import ui.label.LimpidLabel;
import ui.label.ParamLabel;
import utils.ImageUtils;

import java.io.IOException;
import java.util.*;

/**
 * @version V1.0
 * @Title:
 * @Package
 * @Description:
 * @author: runoob
 * @date:
 */
public class VoicePanel extends CommonPanel {

    private LimpidLabel bgLabel = new LimpidLabel(ImageUtils.common,0, 0, WorkPanel.width-10, WorkPanel.height-30);
    private HeaderLabel headerLabel = new HeaderLabel(5, "键", "值");
    private ParamLabel speakLiveRoomLabel;
    private ParamLabel speakDynamicLabel;
    private ParamLabel speakBangumiLabel;
    private ParamLabel danceLabel;
    private ParamLabel clockLabel;
    public Map<Integer, ParamLabel> paramMap = new HashMap<>();

    public VoicePanel() throws IOException {
        this.setBounds(5,81,WorkPanel.width-10,WorkPanel.height-80);
        this.add(headerLabel);
        this.add(bgLabel);
        this.setBorder(null);
    }

    public void setData(List<String> lineList) throws IOException {
        setParamLabel(lineList);
        setParamMap();
        removeComponent();
        addComponent();
        refresh();
    }

    public void setParamLabel(List<String> lineList) throws IOException {
        speakLiveRoomLabel = new ParamLabel(40, 0, "missioncomplete1", "", this, lineList);
        speakDynamicLabel = new ParamLabel(70, 1, "missioncomplete2", "", this, lineList);
        speakBangumiLabel = new ParamLabel(100, 2, "mail", "", this, lineList);
        danceLabel = new ParamLabel(130, 3, "love1", "", this, lineList);
        clockLabel = new ParamLabel(160, 4, "clock", "", this, lineList);
    }

    public void setParamMap(){
        paramMap.put(0, speakLiveRoomLabel);
        paramMap.put(1, speakDynamicLabel);
        paramMap.put(2, speakBangumiLabel);
        paramMap.put(3, danceLabel);
        paramMap.put(4, clockLabel);
    }

    public void removeComponent(){
        this.remove(speakLiveRoomLabel);
        this.remove(speakDynamicLabel);
        this.remove(speakBangumiLabel);
        this.remove(danceLabel);
        this.remove(clockLabel);
        this.remove(headerLabel);
        this.remove(bgLabel);
    }

    public void addComponent(){
        this.add(speakLiveRoomLabel);
        this.add(speakDynamicLabel);
        this.add(speakBangumiLabel);
        this.add(danceLabel);
        this.add(clockLabel);
        this.add(headerLabel);
        this.add(bgLabel);
    }

    public ArrayList<CommonParam> getData(){
        ArrayList<CommonParam> result = new ArrayList<>();
        Set<Map.Entry<Integer, ParamLabel>> entries = paramMap.entrySet();
        for (Map.Entry<Integer, ParamLabel> entry : entries) {
            ParamLabel cache = entry.getValue();
            if (cache.isChosen){
                CommonParam data = new CommonParam();
                data.setId(cache.i);
                data.setKey(cache.key);
                data.setValue(cache.value);
                result.add(data);
            }
        }
        return result;
    }

    public void refresh(){
        this.invalidate();
        this.validate();
        this.repaint();
    }

}
